package com.newy.dao.sys;

import java.util.List;

import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.newy.core.hibernate.HibernateDao;
import com.newy.domain.sys.Dict;

/**
 * 
 * @author linzongxue 2012-2-18
 *
 */
@Repository
public class DictDao extends HibernateDao<Dict, Long> {
	/**
	 * 获取所有字典类型
	 */
	public List<Dict> getAllDictTypes(){
		return this.find(Restrictions.isNull("parentId"), Order.asc("name"));
	}
	
	/**
	 * 通过名称获取字典类型
	 */
	public Dict findTypeByName(String name){
		return this.findUniqueBy("name", name);
	}
	
	/**
	 * 获取指定类型的所有字典项
	 * @param typeId 字典类型ID
	 */
	public List<Dict> getDictItems(Long typeId){
		return this.find(Restrictions.eq("parentId", typeId), Order.asc("value"));
	}
}
